home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
uemlsrc.arc
/
termio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
21KB
|
602 lines
/*
* The functions in this file
* negotiate with the operating system
* for characters, and write characters in
* a barely buffered fashion on the display.
* All operating systems.
*/
#include <stdio.h>
#include <ctype.h>
#include <osbind.h>
#include "ed.h"
#if ST
#define BORDER 0
#define CURSOR 1
#define DESK 2
#define LETTER 3
#define BLACK 0
#define WHITE 0x777
#define COBALT 0x007
#define TEAL 0x055
#define GREEN 0x070
#define GREY 0x555
#define RED 0x700
#define MAGENTA 0x707
#define YELLOW 0x770
/* the first four are the saved values */
int bordcol; /* #0 */
int curscol; /* #1 */
int deskcol; /* #2 */
int letcol; /* #3 */
/* these are the internal values */
int bcolor; /* #0 */
int ccolor; /* #1 */
int dcolor; /* #2 */
int lcolor; /* #3 */
char *colornames[4] = {"Magenta","Magenta","Magenta","Magenta"};
#endif
#if VMS
#include <stsdef.h>
#include <ssdef.h>
#include <descrip.h>
#include <iodef.h>
#include <ttdef.h>
#define NIBUF 128 /* Input buffer size */
#define NOBUF 1024 /* MM says bug buffers win! */
#define EFN 0 /* Event flag */
char obuf[NOBUF]; /* Output buffer */
int nobuf; /* # of bytes in above */
char ibuf[NIBUF]; /* Input buffer */
int nibuf; /* # of bytes in above */
int ibufi; /* Read index */
int oldmode[2]; /* Old TTY mode bits */
int newmode[2]; /* New TTY mode bits */
short iochan; /* TTY I/O channel */
#endif
#if MSDOS
#include <dos.h>
#endif
#if V7
#include <sgtty.h> /* for stty/gtty functions */
struct sgttyb ostate; /* saved tty state */
struct sgttyb nstate; /* values for editor mode */
#endif
/*
* This function is called once
* to set up the terminal device streams.
* On VMS, it translates SYS$INPUT until it
* finds the terminal, then assigns a channel to it
* and sets it raw. On CPM it is a no-op. On the ST
* it is called to update the screen color and every
* time we return from spawn or the term mode.
*/
ttopen()
{
#if VMS
struct dsc$descriptor idsc;
struct dsc$descriptor odsc;
char oname[40];
int iosb[2];
int status;
odsc.dsc$a_pointer = "SYS$INPUT";
odsc.dsc$w_length = strlen(odsc.dsc$a_pointer);
odsc.dsc$b_dtype = DSC$K_DTYPE_T;
odsc.dsc$b_class = DSC$K_CLASS_S;
idsc.dsc$b_dtype = DSC$K_DTYPE_T;
idsc.dsc$b_class = DSC$K_CLASS_S;
do {
idsc.dsc$a_pointer = odsc.dsc$a_pointer;
idsc.dsc$w_length = odsc.dsc$w_length;
odsc.dsc$a_pointer = &oname[0];
odsc.dsc$w_length = sizeof(oname);
status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
exit(status);
if (oname[0] == 0x1B) {
odsc.dsc$a_pointer += 4;
odsc.dsc$w_length -= 4;
}
} while (status == SS$_NORMAL);
status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
if (status != SS$_NORMAL)
exit(status);
status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
exit(status);
newmode[0] = oldmode[0];
newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
exit(status);
#endif
#if ST
static char first = TRUE;
char colornm[80];
register int i;
char temp[40];
if (first)
{
i = 0;
Crawio(0x1b); /* clear and home */
Crawio('E');
bcolor = WHITE; /* border */
strcpy(colorname[i++],"White");
if(!alias(temp,"border"))
insalias("border","white");
ccolor = WHITE; /* cursor */
strcpy(colorname[i++],"White");
if(!alias(temp,"cursor"))
insalias("cursor","white");
dcolor = BLACK; /* screen (desk) */
strcpy(colorname[i++],"Black");
if(!alias(temp,"desk"))
insalias("desk","black");
lcolor = WHITE; /* letters */
strcpy(colorname[i++],"White");
if(!alias(temp,"letter"))
insalias("letter","white");
first = FALSE;
}
/* check for user preferences */
i = 0;
if (alias(colornm,"border"))
{
if (strcmp(colornm,"red")==NULL)
{
bcolor = RED;
strcpy(colornames[0],"Red");
}
else if (strcmp(colornm,"black")==NULL)
{
bcolor = BLACK;
strcpy(colornames[0],"Black");
}
else if (strcmp(colornm,"white")==NULL)
{
bcolor = WHITE;
strcpy(colornames[0],"White");
}
else if (strcmp(colornm,"cobalt")==NULL)
{
bcolor = COBALT;
strcpy(colornames[0],"Cobalt");
}
else if (strcmp(colornm,"green")==NULL)
{
bcolor = GREEN;
strcpy(colornames[0],"Green");
}
else if (strcmp(colornm,"magenta")==NULL)
{
bcolor = MAGENTA;
strcpy(colornames[0],"Magenta");
}
else if (strcmp(colornm,"yellow")==NULL)
{
bcolor = YELLOW;
strcpy(colornames[0],"Yellow");
}
else if (strcmp(colornm,"grey")==NULL)
{
bcolor = GREY;
strcpy(colornames[0],"Grey");
}
else if (strcmp(colornm,"teal")==NULL)
{
bcolor = TEAL;
strcpy(colornames[0],"Teal");
}
}
if (alias(colornm,"cursor"))
{
if (strcmp(colornm,"red")==NULL)
{
ccolor = RED;
strcpy(colornames[1],"Red");
}
else if (strcmp(colornm,"black")==NULL)
{
ccolor = BLACK;
strcpy(colornames[1],"Black");
}
else if (strcmp(colornm,"white")==NULL)
{
ccolor = WHITE;
strcpy(colornames[1],"White");
}
else if (strcmp(colornm,"cobalt")==NULL)
{
ccolor = COBALT;
strcpy(colornames[1],"Cobalt");
}
else if (s